import Vue from 'vue'
import Router from 'vue-router'
import Login from '@/components/login.vue'
import Home from '@/components/home.vue'
import CreatNews from '@/components/creat_news.vue'
import ReivseNews from '@/components/revise_news.vue'
import CreatRecruitment from '@/components/creat_recruitment.vue'
import ReivseRecruitment from '@/components/revise_recruitment.vue'
import NewsList from '@/components/newsList.vue'
import RecruitmentList from '@/components/recruitmentList.vue'
import RecycleBinNews from '@/components/recycleBinNews.vue'
import RecycleBinRecruitment from '@/components/recycleBinRecruitment.vue'
import Project_introduction from '@/components/project_introduction.vue'
import RecycleBinProject from '@/components/recycleBinProject.vue'
import CreatProject from '@/components/creat_project.vue'
import ReivseProject from '@/components/revise_project.vue'
import SeeNews from '@/components/seeNews.vue'
import SeeRecruitment from '@/components/seeRecuitment.vue'
import SeeProject from '@/components/seeProject.vue'
import ProductServiceList from '@/components/productServiceList.vue'
import PartyBuildingList from '@/components/partyBuildingList.vue'
import RecycleBinParty from '@/components/recycleBinParty.vue'
import RecycleBinProduct from '@/components/recycleBinProduct.vue'
import SeeProduct from '@/components/seeProduct.vue'
import SeeParty from '@/components/seeParty.vue'
import CreatProduct from '@/components/creat_product.vue'
import ReviseProduct from '@/components/revise_product.vue'
import CreatPartyBuilding from '@/components/creat_partyBuilding.vue'
import RevisePartyBuilding from '@/components/revise_partyBuilding.vue'

Vue.use(Router)

 const router = new Router({
  routes: [
    {path:'/',redirect:'/login'},
    {path:'/login',component:Login},
    {
    path:'/home',
    component:Home,
    redirect: '/newsList',
    children:[{name:'newsList',path:'/newsList',component: NewsList},
              {name:'recruitmentList',path:'/recruitmentList',component: RecruitmentList},
              {name:'creat_news',path:'/creat_news',component: CreatNews},
              {name:'revise_news',path:'/revise_news',component:ReivseNews},
              {name:'creat_recruitment',path:'/creat_recruitment',component: CreatRecruitment},
              {name:'reivse_recruitment',path:'/reivse_recruitment',component: ReivseRecruitment},
              {name:'recycle_binNews',path:'/recycle_binNews',component: RecycleBinNews},
              {name:'recycle_binRecruitment',path:'/recycle_binRecruitment',component: RecycleBinRecruitment},
              {name:'project_introduction',path:'/project_introduction',component: Project_introduction},
              {name:'recycleBinProject',path:'/recycleBinProject',component: RecycleBinProject},
              {name:'creat_project',path:'/creat_project',component: CreatProject},
              {name:'revise_project',path:'/revise_project',component: ReivseProject},
              {name:'seeNews',path:'/seeNews',component: SeeNews},
              {name:'seeRecruitment',path:'/seeRecruitment',component: SeeRecruitment},
              {name:'seeProject',path:'/seeProject',component: SeeProject},
              {name:'productServiceList',path:'/productServiceList',component: ProductServiceList},
              {name:'partyBuildingList',path:'/partyBuildingList',component: PartyBuildingList},
              {name:'recycleBinParty',path:'/recycleBinParty',component: RecycleBinParty},
              {name:'recycleBinProduct',path:'/recycleBinProduct',component: RecycleBinProduct},
              {name:'seeProduct',path:'/seeProduct',component: SeeProduct},
              {name:'seeParty',path:'/seeParty',component: SeeParty},
              {name:'creat_product',path:'/creat_product',component: CreatProduct},
              {name:'revise_product',path:'/revise_product',component: ReviseProduct},
              {name:'creat_partyBuilding',path:'/creat_partyBuilding',component:CreatPartyBuilding},
              {name:'revise_partyBuilding',path:'/revise_partyBuilding',component:RevisePartyBuilding}
    ]}
  ]
})

//挂载导航守卫
router.beforeEach((to, from, next)=> {
  // to 将要访问的路径
  // from 代表从哪个路径跳转而来
  // next 是一个函数，表示放行
  if(to.path === '/login') return next()
  // 获取state
  const code = window.sessionStorage.getItem('code')
  if(!code) return next('/login')
  else{
    return next()
  }
})

export default router
